$(window).load(function () {
    $(".loading").fadeOut()
})
var allData;
$(function () {
    $.ajax({
        url: '/system/post/listAll',
        type: "post",
        dataType: "json",
        success: function (res) {
            if (res.code === 0) {
                allData = res.data;
                var javaAll = 0,
                    htmlAll = 0,
                    bigdataAll = 0,
                    testAll = 0,
                    uiAll = 0;

                var javaAllPro,
                    htmlAllPro,
                    bigdataAllPro,
                    testAllPro,
                    uiAllPro;


                var undergraduateAll = 0,
                    postgradAll = 0,
                    highschoolAll = 0,
                    juniorAll = 0,
                    nolimitAll = 0;
                var undergraduateAllPro,
                    postgradAllPro,
                    highschoolAllPro,
                    juniorAllPro,
                    nolimitAllPro;

                var oneSalary = 0,
                    twoSalary = 0,
                    threeSalary = 0,
                    fourSalary = 0,
                    fiveSalary = 0,
                    sixSalary = 0;

                var oneExperience = 0,
                    twoExperience = 0,
                    threeExperience = 0,
                    fourExperience = 0,
                    fiveExperience = 0;

                var beijingCity = 0,
                    shanghaiCity = 0,
                    guanzhouCity = 0;

                for (let i = 0; i < allData.length; i++) {
                    switch (allData[i].positionName) {
                        case "Java开发":
                            javaAll++;
                            break;
                        case "前端开发" :
                            htmlAll++;
                            break;
                        case "大数据" :
                            bigdataAll++;
                            break;
                        case "软件测试" :
                            testAll++;
                            break;
                        case "UI设计师" :
                            uiAll++;
                            break;
                    }
                    switch (allData[i].education) {
                        case "本科":
                            undergraduateAll++;
                            break;
                        case "研究生" :
                            postgradAll++;
                            break;
                        case "高中" :
                            highschoolAll++;
                            break;
                        case "大专" :
                            juniorAll++;
                            break;
                        case "学历不限" :
                            nolimitAll++;
                            break;
                    }
                    switch (allData[i].salary) {
                        case "0-5K":
                            oneSalary++;
                            break;
                        case "5-10K":
                            twoSalary++;
                            break;
                        case "10-20K":
                            threeSalary++;
                            break;
                        case "20-30K":
                            fourSalary++;
                            break;
                        case "30-40K":
                            fiveSalary++;
                            break;
                        case "40K+":
                            sixSalary++;
                            break;
                        default:
                            console.log(7);
                            break;
                    }
                    switch (allData[i].workYear) {
                        case "经验不限":
                            oneExperience++;
                            break;
                        case "1年":
                            twoExperience++;
                            break;
                        case "1-3年":
                            threeExperience++;
                            break;
                        case "3-5年":
                            fourExperience++;
                            break;
                        case "5-10年" || "5年以上":
                            fiveExperience++;
                            break;
                        default:
                            console.log(8);
                            break;
                    }
                    switch (allData[i].city) {
                        case "北京":
                            beijingCity++;
                            break;
                        case "上海":
                            shanghaiCity++;
                            break;
                        case "广州":
                            guanzhouCity++;
                            break;
                    }
                }
                javaAllPro = Math.floor(javaAll / res.total * 100);
                htmlAllPro = Math.floor(htmlAll / res.total * 100);
                bigdataAllPro = Math.floor(bigdataAll / res.total * 100);
                testAllPro = Math.floor(testAll / res.total * 100);
                uiAllPro = Math.floor(uiAll / res.total * 100);

                undergraduateAllPro = Math.floor(undergraduateAll / res.total * 100);
                postgradAllPro = Math.floor(postgradAll / res.total * 100);
                highschoolAllPro = Math.floor(highschoolAll / res.total * 100);
                juniorAllPro = Math.floor(juniorAll / res.total * 100);
                nolimitAllPro = Math.floor(nolimitAll / res.total * 100);


                // 左1
                echarts_5();

                function echarts_5() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('echart5'));
                    var lightBlue = {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: 'rgba(41, 121, 255, 1)'
                        }, {
                            offset: 1,
                            color: 'rgba(0, 192, 255, 1)'
                        }],
                        globalCoord: false
                    }

                    var option = {
                        tooltip: {
                            show: false
                        },
                        grid: {
                            top: '0%',
                            left: '65',
                            right: '14%',
                            bottom: '0%',
                        },
                        xAxis: {
                            min: 0,
                            max: 100,
                            splitLine: {
                                show: false
                            },
                            axisTick: {
                                show: false
                            },
                            axisLine: {
                                show: false
                            },
                            axisLabel: {
                                show: false
                            }
                        },
                        yAxis: {
                            data: ['UI设计师', '软件测试', '大数据', '前端开发', 'Java开发'],
                            //offset: 15,
                            axisTick: {
                                show: false
                            },
                            axisLine: {
                                show: false
                            },
                            axisLabel: {
                                color: 'rgba(255,255,255,.6)',
                                fontSize: 14
                            }
                        },
                        series: [{
                            type: 'bar',
                            label: {
                                show: true,
                                zlevel: 10000,
                                position: 'right',
                                padding: 10,
                                color: '#49bcf7',
                                fontSize: 14,
                                formatter: '{c}%'

                            },
                            itemStyle: {
                                color: '#49bcf7'
                            },
                            barWidth: '15',
                            data: [uiAllPro, testAllPro, bigdataAllPro, htmlAllPro, javaAllPro],
                            z: 10
                        }, {
                            type: 'bar',
                            barGap: '-100%',
                            itemStyle: {
                                color: '#fff',
                                opacity: 0.1
                            },
                            barWidth: '15',
                            data: [100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100],
                            z: 5
                        }],
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }

                // 左三
                echarts_1();

                function echarts_1() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('echart1'));
                    option = {
                        tooltip: {
                            trigger: 'item',
                            formatter: "{b} : {c} ({d}%)"
                        },
                        legend: {
                            right: 0,
                            top: 30,
                            height: 160,
                            itemWidth: 10,
                            itemHeight: 10,
                            itemGap: 10,
                            textStyle: {
                                color: 'rgba(255,255,255,.6)',
                                fontSize: 12
                            },
                            orient: 'vertical',
                            data: ['本科', '研究生', '高中', '大专', '不限']
                        },
                        calculable: true,
                        series: [
                            {
                                name: ' ',
                                color: ['#62c98d', '#2f89cf', '#4cb9cf', '#53b666', '#62c98d', '#205acf', '#c9c862', '#c98b62', '#c962b9', '#7562c9', '#c96262', '#c25775', '#00b7be'],
                                type: 'pie',
                                radius: [30, 70],
                                center: ['35%', '50%'],
                                roseType: 'radius',
                                label: {
                                    normal: {
                                        show: true
                                    },
                                    emphasis: {
                                        show: true
                                    }
                                },

                                lableLine: {
                                    normal: {
                                        show: true
                                    },
                                    emphasis: {
                                        show: true
                                    }
                                },

                                data: [
                                    {value: undergraduateAllPro, name: '本科'},
                                    {value: postgradAllPro, name: '研究生'},
                                    {value: highschoolAllPro, name: '高中'},
                                    {value: juniorAllPro, name: '大专'},
                                    {value: nolimitAllPro, name: '不限'},

                                ]
                            },
                        ]
                    };

                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }

                // 右1
                var companySize = [];
                var companySize1 = [];
                var index;
                table1();

                function table1() {
                    for (let i = 0; i < allData.length; i++) {
                        companySize[i] = allData[i].companySize.slice(0, -1);
                        if (companySize[i].includes("-")) {
                            index = companySize[i].indexOf("-");
                            allData[i].num = companySize[i].slice(index + 1);
                            // console.log(companySize[i].slice(index+1))
                        }else {
                            allData[i].num = companySize[i];
                        }
                    }
                    // 倒序排序
                    // console.log(companySize)
                    var companySize2 = [];
                    companySize2 = allData.sort((x, y) => y.num - x.num);
                    var list = companySize2.slice(0,5);
                    // console.log(list)
                    for (let i = 0; i < list.length; i++) {
                        $("#table1 tbody").append(`<tr><td><span>${i + 1}</span></td><td>${list[i].companyFullName}</td><td>${list[i].num}<br></td><td>100%<br></td></tr>`)
                    }
                    // console.log(companySize1)
                }

                // 右2
                echarts_6();

                function echarts_6() {
                    var chartDom = document.getElementById('echart6');
                    var myChart = echarts.init(chartDom);
                    var option;

                    option = {
                        xAxis: {
                            type: 'category',
                            data: ['0-5k', '5-10k', '10-20k', '20-30k', '30-40k', '40k+'],
                            axisLine: {
                                lineStyle: {
                                    color: '#fff'
                                }
                            }

                        },
                        yAxis: {
                            type: 'value',
                            axisLine: {
                                lineStyle: {
                                    color: '#fff'
                                }
                            }
                        },
                        series: [
                            {
                                data: [oneSalary, twoSalary, threeSalary, fourSalary, fiveSalary, sixSalary],
                                type: 'bar',

                                // showBackground: true,
                                backgroundStyle: {
                                    color: 'rgba(180, 180, 180, 0.2)'
                                },
                                fontSize: 200,
                                itemStyle: {
                                    color: "#49bcf7"
                                }
                            }
                        ]
                    };
                    option && myChart.setOption(option);


                }

                // 右3
                echarts_2();

                function echarts_2() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('echart2'));

                    option = {
                        tooltip: {
                            trigger: 'item',
                            formatter: "{b} : {c} ({d}%)"
                        },
                        legend: {

                            top: '15%',
                            data: ['不限', '1年', '1-3年', '3-5年', '5年以上'],
                            icon: 'circle',
                            textStyle: {
                                color: 'rgba(255,255,255,.6)',
                            }
                        },
                        calculable: true,
                        series: [{
                            name: '',
                            color: ['#62c98d', '#2f89cf', '#4cb9cf', '#53b666', '#62c98d', '#205acf', '#c9c862', '#c98b62', '#c962b9', '#c96262'],
                            type: 'pie',
                            //起始角度，支持范围[0, 360]
                            startAngle: 0,
                            //饼图的半径，数组的第一项是内半径，第二项是外半径
                            radius: [51, 100],
                            //支持设置成百分比，设置成百分比时第一项是相对于容器宽度，第二项是相对于容器高度
                            center: ['50%', '45%'],

                            //是否展示成南丁格尔图，通过半径区分数据大小。可选择两种模式：
                            // 'radius' 面积展现数据的百分比，半径展现数据的大小。
                            //  'area' 所有扇区面积相同，仅通过半径展现数据大小
                            roseType: 'area',
                            //是否启用防止标签重叠策略，默认开启，圆环图这个例子中需要强制所有标签放在中心位置，可以将该值设为 false。
                            avoidLabelOverlap: false,
                            label: {
                                normal: {
                                    show: true,
                                    //  formatter: '{c}辆'
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            labelLine: {
                                normal: {
                                    show: true,
                                    length2: 1,
                                },
                                emphasis: {
                                    show: true
                                }
                            },
                            data: [
                                {value: oneExperience, name: '不限',},
                                {value: twoExperience, name: '1年',},
                                {value: threeExperience, name: '1-3年',},
                                {value: fourExperience, name: '3-5年',},
                                {value: fiveExperience, name: '5年以上',},


                                {value: 0, name: "", label: {show: false}, labelLine: {show: false}},
                                {value: 0, name: "", label: {show: false}, labelLine: {show: false}},
                                {value: 0, name: "", label: {show: false}, labelLine: {show: false}},
                                {value: 0, name: "", label: {show: false}, labelLine: {show: false}},
                                {value: 0, name: "", label: {show: false}, labelLine: {show: false}},


                            ]
                        }]
                    };

                    // 使用刚指定的配置项和数据显示图表。
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }

                // 中间-北京城市
                zb1();

                function zb1() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('zb1'));
                    var v1 = beijingCity;//在北京
                    var v3 = allData.length;//总数
                    var v2 = v3 - v1;//未在北京
                    option = {
                        series: [{
                            type: 'pie',
                            radius: ['60%', '70%'],
                            color: '#49bcf7',
                            label: {
                                normal: {
                                    position: 'center'
                                }
                            },
                            data: [{
                                value: v1,
                                name: '在北京',
                                label: {
                                    normal: {
                                        formatter: v1 + '',
                                        textStyle: {
                                            fontSize: 20,
                                            color: '#fff',
                                        }
                                    }
                                }
                            }, {
                                value: v2,
                                name: '未在北京',
                                label: {
                                    normal: {
                                        formatter: function (params) {
                                            return '占比' + Math.round(v1 / v3 * 100) + '%'

                                        },
                                        textStyle: {
                                            color: '#aaa',
                                            fontSize: 12
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: 'rgba(255,255,255,.2)'
                                    },
                                    emphasis: {
                                        color: '#fff'
                                    }
                                },
                            }]
                        }]
                    };
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }

                // 中间-上海城市
                zb2();

                function zb2() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('zb2'));
                    var v1 = shanghaiCity;//在上海
                    var v3 = allData.length;//总数
                    var v2 = v3 - v1;//未在上海
                    option = {
                        series: [{
                            type: 'pie',
                            radius: ['60%', '70%'],
                            color: '#49bcf7',
                            label: {
                                normal: {
                                    position: 'center'
                                }
                            },
                            data: [{
                                value: v1,
                                name: '在上海',
                                label: {
                                    normal: {
                                        formatter: v1 + '',
                                        textStyle: {
                                            fontSize: 20,
                                            color: '#fff',
                                        }
                                    }
                                }
                            }, {
                                value: v2,
                                name: '未在上海',
                                label: {
                                    normal: {
                                        formatter: function (params) {
                                            return '占比' + Math.round(v1 / v3 * 100) + '%'

                                        },
                                        textStyle: {
                                            color: '#aaa',
                                            fontSize: 12
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: 'rgba(255,255,255,.2)'
                                    },
                                    emphasis: {
                                        color: '#fff'
                                    }
                                },
                            }]
                        }]
                    };
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }


                // 中间-广州城市
                zb3();

                function zb3() {
                    // 基于准备好的dom，初始化echarts实例
                    var myChart = echarts.init(document.getElementById('zb3'));
                    var v1 = guanzhouCity;//在广州
                    var v3 = allData.length;//总数
                    var v2 = v3 - v1;//未在广州
                    option = {
                        series: [{
                            type: 'pie',
                            radius: ['60%', '70%'],
                            color: '#49bcf7',
                            label: {
                                normal: {
                                    position: 'center'
                                }
                            },
                            data: [{
                                value: v1,
                                name: '在广东',
                                label: {
                                    normal: {
                                        formatter: v1 + '',
                                        textStyle: {
                                            fontSize: 20,
                                            color: '#fff',
                                        }
                                    }
                                }
                            }, {
                                value: v2,
                                name: '未在广东',
                                label: {
                                    normal: {
                                        formatter: function (params) {
                                            return '占比' + Math.round(v1 / v3 * 100) + '%'

                                        },
                                        textStyle: {
                                            color: '#aaa',
                                            fontSize: 12
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        color: 'rgba(255,255,255,.2)'
                                    },
                                    emphasis: {
                                        color: '#fff'
                                    }
                                },
                            }]
                        }]
                    };
                    myChart.setOption(option);
                    window.addEventListener("resize", function () {
                        myChart.resize();
                    });
                }

                // map();
                //
                // function map() {
                //     const data_list = [{name: '江苏', value: 192836}, {name: '安徽', value: 118491}, {
                //         name: '湖北',
                //         value: 117036
                //     }, {name: '湖南', value: 110666}, {name: '广东', value: 109915}, {name: '浙江', value: 69540}, {
                //         name: '福建',
                //         value: 45146
                //     }, {name: '山东', value: 42753}, {name: '河南', value: 31141}, {name: '四川', value: 30287}, {
                //         name: '河北',
                //         value: 29890
                //     }, {name: '江西', value: 23649}, {name: '黑龙江', value: 20475}, {name: '陕西', value: 17942}, {
                //         name: '贵州',
                //         value: 16019
                //     }, {name: '吉林', value: 15441}, {name: '广西', value: 11875}, {name: '山西', value: 11077}, {
                //         name: '云南',
                //         value: 9238
                //     }, {name: '辽宁', value: 6538}, {name: '甘肃', value: 6128}, {name: '重庆', value: 5883}, {
                //         name: '内蒙古',
                //         value: 5605
                //     }, {name: '海南', value: 4596}, {name: '天津', value: 4244}, {name: '新疆', value: 4125}, {
                //         name: '上海',
                //         value: 3429
                //     }, {name: '宁夏', value: 3225}, {name: '青海', value: 1833}, {name: '北京', value: 1765}]
                //     const data_value_list = [192836, 118491, 117036, 110666, 109915, 69540, 45146, 42753, 31141, 30287, 29890, 23649, 20475, 17942, 16019, 15441, 11875, 11077, 9238, 6538, 6128, 5883, 5605, 4596, 4244, 4125, 3429, 3225, 1833, 1765, 0,]
                //     const option = {
                //         title: {
                //             text: '全国工作招聘数量',
                //             subtext: '数据源：前程无忧',
                //             x: 'center',
                //             textStyle: {
                //                 fontSize: 40,
                //
                //             },
                //             subtextStyle: {
                //                 fontSize: 20,
                //             },
                //         },
                //         tooltip: {
                //             trigger: 'item',
                //             formatter: '名称：{a}<br/>省份：{b}<br/>数值：{c}'
                //         },
                //
                //         dataRange: {
                //             min: 0,
                //             max: Math.max.apply(null, data_value_list),
                //             x: 'left',
                //             y: 'bottom',
                //             text: ['高', '低'],           // 文本，默认为数值文本
                //             calculable: true,
                //             //inRange: {
                //             //    color: ['#FFFFFF','#0000FF'],
                //             //    symbolSize: [10, 100]
                //             //}
                //         },
                //         series: [
                //             {
                //                 name: '数据',
                //                 type: 'map',
                //                 mapType: 'china',
                //                 roam: false,
                //                 itemStyle: {
                //                     normal: {label: {show: true}},
                //                     emphasis: {label: {show: true}}
                //                 },
                //                 data: data_list
                //             }
                //         ]
                //     };
                //     ec_map = echarts.init(document.getElementById('china_map'));
                //     ec_map.setOption(option)
                //
                // };


            }


            return allData;
        }

    })
    // 左二
    $.ajax({
        url: '/system/notice/list',
        type: "post",
        dataType: "json",
        success: function (res) {
            if (res.code === 0) {
                // console.log(res);
                var allFormData = res.rows;
                for (let i = 0; i < allFormData.length; i++) {
                    $("#wrapList").append(`<li><span>${res.rows[allFormData.length - (i + 1)].noticeTitle}</span><span>${res.rows[allFormData.length - (i + 1)].createTime.slice(0, 10)}</span></li>`)
                }
            }
        }

    })

    // 地图
    $.ajax({
        url: '/system/main/chinaMapData',
        type: "get",
        dataType: "json",
        success: function (res) {
            if (res.code === 0) {
                console.log(res);

                map();
                function map() {
                    function unique (arr) {
                        return Array.from(new Set(arr));
                    }
                    const data_list = res.data;
                    const data_value_list = [];
                    for (let i = 0; i < data_list.length; i++) {
                        data_value_list[i] =res.data[i].value;
                    }
                    unique(data_value_list.sort((x,y)=>y-x));
                    const option = {
                        title: {
                            text: '全国工作招聘数量',
                            subtext: '数据源：前程无忧',
                            x: 'center',
                            textStyle: {
                                fontSize: 40,

                            },
                            subtextStyle: {
                                fontSize: 20,
                            },
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '名称：{a}<br/>省份：{b}<br/>数值：{c}'
                        },

                        dataRange: {
                            min: 0,
                            max: Math.max.apply(null, data_value_list),
                            x: 'left',
                            y: 'bottom',
                            text: ['高', '低'],           // 文本，默认为数值文本
                            calculable: true,
                        },
                        series: [
                            {
                                name: '数据',
                                type: 'map',
                                mapType: 'china',
                                roam: false,
                                itemStyle: {
                                    normal: {label: {show: true}},
                                    emphasis: {label: {show: true}}
                                },
                                data: data_list
                            }
                        ]
                    };
                    ec_map = echarts.init(document.getElementById('china_map'));
                    ec_map.setOption(option)

                };
            }
        }

    })

    return allData;
})


















